package org.bt.common.validator;

import org.bt.common.validator.aspect.NotBlank;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * Check that a character sequence is not {@code null} nor empty after removing any leading or trailing whitespace
 * <p>
 * Created on 2020/1/9
 *
 * @author tongw
 */
public class NotBlankValidator implements ConstraintValidator<NotBlank, CharSequence> {

    public NotBlankValidator() {
    }

    @Override
    public boolean isValid(CharSequence charSequence, ConstraintValidatorContext constraintValidatorContext) {
        if (charSequence == null) {
            return false;
        } else {
            return charSequence.toString().trim().length() > 0;
        }
    }
}
